<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<div align="center">
		<h2>驾校信息修改</h2>
		<p>
			驾校名称：<input type="text" name="" id="name" value="" />*
		</p>
		<p>
			所在城区：<select id="chengqu">
				<option id="xuanzhong" value="0">请选择</option>
			</select>
		</p>
		<p>
			地址：<input type="text" name="" id="address" value="" />
		</p>
		<p>
			联系电话：<input type="text" name="" id="phone" value="" />
		</p>
		<button id="tj">修改</button>&nbsp;&nbsp;<button id="cz">重置</button>&nbsp;&nbsp;<button id="ff">返回</button>
	</div>
</body>
<script type="text/javascript" src="/Maven_jiaxiao_war_exploded/js/jquery2.2.4.js"></script>
<script type="text/javascript">
	function getUrlParam(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for(var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if(pair[0] == variable) { return pair[1]; }
		}
		return(false);
	}
	var id = getUrlParam("id");
	var cid = getUrlParam("cid");
	$.ajax({
		"url":"/Maven_jiaxiao_war_exploded/xiala",
		"type":"get",
		"dataType":"json",
		"success":function(pd){
			for (var i=0;i<pd.length;i++){
				if(cid==pd[i].id){
					$("xuanzhong").html(pd[i].name);
				}
				$("#chengqu").append("<option value="+pd[i].id+">"+pd[i].name+"</option>");
			}
		}
	})
	$.ajax({
		"url":"/Maven_jiaxiao_war_exploded/cha",
		"type":"get",
		"data":{"id":id},
		"dataType":"json",
		"success":function(pd){
			$("#name").val(pd.name);
			$("#address").val(pd.address);
			$("#phone").val(pd.phone);
		}
	})
	$("#cz").click(function () {
		$("#name").val("")
		$("#address").val("")
		$("#phone").val("")

	})
	$("#ff").click(function () {
	window.location.href="/Maven_jiaxiao_war_exploded/index.html"
	})
	$("#tj").click(function () {
		var name=$("#name").val();
		var chengqu=$("#chengqu").val();
		var address=$("#address").val();
		var phone=$("#phone").val();
		if(name==""){
			alert("不能为空")
		}else if(address==""){
			alert("不能为空")
		}else if(phone==""){
			alert("不能为空")
		}else if(chengqu==0){
			alert("请选择地区")
		}else{
		$.ajax({
			"url":"/Maven_jiaxiao_war_exploded/xiugai",
			"type":"get",
			"data":{"id":id,"name":name,"chengqu":chengqu,"address":address,"phone":phone},
			"dataType":"text",
			"success":function(pd){
				if(pd.indexOf("true")>-1){
		  			alert("修改成功");
	        		window.location.href="index.html";
		  		}else{
		  			alert("添加失败");
		  		}
			}
		})
		}
	})
	
	</script>
</html>